<?php
/**
 * @author wyl
 * @date 2015-12-16 09:13:58
 * @param $args 0:间隔时间 1:测试用户数目(脚本数)
 */
Yii::import('dao.bidAuction.BidAuction');
Yii::import('dao.CustomerInfoDao');
class PresureTestCommand extends CConsoleCommand{
  	const PRESURE_TEST_INTERVAL=10;
    public $endTime;
    public $testCount=10;
    public $auctionId;
    
	public function run($args){
	   $this->endTime=time()+self::PRESURE_TEST_INTERVAL; 
	   if (!empty($args[0])){
	       $this->endTime=time()+$args[0];
	   }
	   
	   if (!empty($args[1])){
	       $this->testCount=$args[1];
	   }
	   
	   $customerList=new CustomerInfoDao();
	   $customerList=$customerList->getCustomers(array(
	       'count'=>$this->testCount
	   ));
	   
	   $this->auctionId=$args[2];
	   
	   if (count($customerList)<$this->testCount){
	       $this->testCount=count($customerList);
	   }
	   
	   for ($i=0;$i<$this->testCount;$i++){
	       /*windows execute*/
	       //$executeStr='php -q '.Yii::app()->basePath.'\yiic presureworker  ';
	       /*linux execute*/
	       $executeStr='nohup  '.Yii::app()->basePath.'/./yiic presureworker  ';
	       exec($executeStr.$this->endTime.'  '.$customerList[$i]['id'].' '.$this->auctionId.' >'.$customerList[$i]['id'].'.log 2>&1  &');
	       echo $i;
	   }
  	}
  	
  	
}